0

the below query works fine in mongodb:

db.article.find({$and:[{"version":1},{"targetGroup" : ["ecpa"]},{"state":"published"}]}).limit(5).pretty()

But when i am running it from python it throws error as invalid syntax:

from pymongo import MongoClient
import pprint

client = MongoClient('127.0.0.1', 27300)
db = client['data']
article= db.article

articles = article.find({$and:[{"version":1},{"targetGroup" : ["ecpa"]},{"state":"published"}]})
for item in articles:
    pprint.pprint(item)

what do i need to change to make this work?

num3ri
  • 822
  • 16
  • 20
Soubhik Banerjee
  • 421
  • 4
  • 8
  • 17

1 Answers1

2

in pymongo the $and operator should be in a string, so articles = article.find({"$and":[{"version":1},{"targetGroup" : ["ecpa"]},{"state":"published"}]}) should work.

Any way, next time you should post the whole error you get, so that it would be easier to answer

Hagai
  • 678
  • 7
  • 20