Does Mongo know what tuples are?
Asked Answered
A

2

5

I'm storing lists of tuples into a MongoDB database using PyMongo. For some reason, when I view the data in the mongo shell, the tuples are represented by square brackets.

In addition, when I extract the data from the database and check its type(), python tells me it's a list.

Is it possible to store a tuple in a mongo database?

Apology answered 9/1, 2018 at 20:19 Comment(0)
R
7

No, Mongo actually uses a BSON-like structure so it does not support tuples. That is why PyMongo converts them for you to lists. Of course, you can convert them back to tuples when you load them from Mongo. As you can see from the link above, many types are supported, the most common ones being:

  • Double
  • String
  • Object
  • Array
  • Binary data
  • Boolean
  • Date
  • Null
  • Regular Expression
Roll answered 9/1, 2018 at 20:28 Comment(0)
W
0

Yes, you can, but the first element of a tuple have to be a String. like {"element_1_Name": value, "element_2_Name": value, "element_3_Name": value, ...}

{
 "manufacturer": "Dixell",
 "model": "XW764K",
 "name": "Dixell ifi",
 "version": "v2.7",
 "parameters": {
        "pb1": 256,
        "pb2": 258,
        "pb3": 260,
        "sp": 868,
        "us": 768,
        "hs": 769
        ......
    }
}
Willed answered 14/5 at 0:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.