Search code examples
arraysjsonmongodbmongoimport

How to store a number array in MongoDB


I am looking to store an array of individual lotto drawn numbers within a MongoDB document.

Neither of the below structures work. Can anyone point out the correct way to form JSON to facilitate this type of storage?

[{
    "date":"2014-02-10T10:50:42.389Z",
    "numbers":{
        [10,20,30,40,12,31,35]
    }
}]

[{
"date":"2014-02-10T10:50:42.389Z",
    "numbers":{
        10,20,30,40,12,31,35
    }
}]

I am looking to import this document as a Mongo document and ultimately build on it after that.


Solution

  • db.x.insert({"date" : new ISODate() ,"numbers":[1,2,3]}) should work.