0

For example, the mongo document as follows:

{
    "_id": ObjectId("xxx"),
    "array": [
        0,
        1,
        [2, 3],
        4
    ]
}

Is there a method to get the 2 from the document?

Amiram Korach
  • 13,056
  • 3
  • 28
  • 30
stamaimer
  • 6,227
  • 5
  • 34
  • 55
  • I imagine the solution would be very close to the solution here http://stackoverflow.com/questions/13452745/extract-subarray-value-in-mongodb – react_or_angluar Oct 31 '16 at 06:01
  • 1
    By `get the 2` you mean "find the documents that has a 2 there" or "select only the 2 from the document in the query"? What is the context that you need it? is it a batch? how many data? there might be simple solutions but they are not so fast. – Amiram Korach Oct 31 '16 at 06:10
  • @AmiramKorach It means select only 3 from the document. There are 3000+ records. – stamaimer Oct 31 '16 at 09:18
  • Where are you trying to do it? node? mongo shell? – Amiram Korach Oct 31 '16 at 10:02
  • @AmiramKorach python with pymongo – stamaimer Nov 01 '16 at 02:10
  • If you have only 3000 records and you can wait for the answer, you can do a simple forEach, but I don't know if you can do it with pymongo or you have to use the shell. – Amiram Korach Nov 01 '16 at 06:09

0 Answers0