0

I have a collection of mongoDB entries like the one below...

{
  "_id": ObjectId("4e2a4ca7f21a81331f0006c3"),
  "users": {
    "bob": 1375496448, "alice": 1375496448
  },
  ...other values...
}

I am looking for a simple query for me to find all entries...
1) Without user x in users
2) With user x in users where the corresponding value is < y

I hope this question is not too trivial, but I just started learning mongoDB this afternoon and I would like to get it up and running in a simple server I am planning to set up. Thanks!

Matt Olan
  • 1,911
  • 1
  • 18
  • 27
  • Could you please provide more info on the collection. It's hard to query the collection without a better idea of the collections structure. Cheers – dcodesmith Aug 03 '13 at 08:11
  • The struct I am using for this collection is Address string, Port string, Timestamp int, Users map[string]int I need to have a query to return the union of the 2 cases listed above. I hope this helps! :D – Matt Olan Aug 03 '13 at 23:02

2 Answers2

2

Assuming your collection is named users.

1)db.users.find({'users.X':{$exists:false}})

2)db.users.find({'users.X':{$lt:y}})

Ishaan
  • 886
  • 6
  • 12
2

Ishaan's answer should work for you. I am only adding a way to Union the two queries.

db.users.find( {$or: [ {'users.X':{$exists:false}}, {'users.X':{$lt:y}} ] } )

You will find documentation of operators like $or, $and, etc. on this page.

shshank
  • 2,571
  • 1
  • 18
  • 27