Skip to content Skip to sidebar Skip to footer

Insert Array Into Mongodb Using Pymongo

I am trying to add array into mongdb using pymongo I have another program that will return something like ['1 aksdfjas;dkfjsa;dfkj','2 ;alksdjf;askdjf;asdfjkasdf', '3 ;alksdfj;asd

Solution 1:

First, change how you are constructing the string from tGenerator method to below:

returnString += str(i+1) + " " + stringToStuff + ","

Second, you can use the split method to do the required, so your insertion will look something like below:

post = {
    "name":name2,
    "score":8,
    "date":datetime.datetime.now(),
    "output": tGenerator(createLoop()).split(',')
}
collection2.insert_one(post)

I hope, the above works for you.

Post a Comment for "Insert Array Into Mongodb Using Pymongo"