0

I would like to make a query in Mongo through the Python Shell

query2 = (
  {
    "itemId":{"$in": List},
  "startDate" : {"$gt": start_date} 
  },
  {"a":1, 'b':1, 'startDate':1}
)

List has this format

[u'abcd1',
 u'abcd2',
 u'abcd3']

Pb: It returns 0

I guess it's because in my Mongo DB the itemId has this format :

ObjectId("abcd1")

Tried this

portsList = map(lambda x: "ObjectId('" +  x +"')", portsList)

But it won't work

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
Hannah Mse
  • 61
  • 1
  • 6
  • It's not a string. There is actually an [`ObjectId`](http://api.mongodb.com/python/current/api/bson/objectid.html) function to import which returns the correct type. – Neil Lunn Jun 18 '17 at 08:17
  • can you be more specific? I really am a beginner in Python and dont find anything on this function on google – Hannah Mse Jun 18 '17 at 08:20
  • [Read the linked answer](https://stackoverflow.com/questions/30407166/how-to-convert-hex-string-to-objectid-in-python). You import the function and then use that in your lambda expression instead of concatenating as a "string". – Neil Lunn Jun 18 '17 at 08:22

0 Answers0