S
S
Sergo Sergo2015-04-19 13:51:57
MongoDB
Sergo Sergo, 2015-04-19 13:51:57

How to add an object to the database?

I am writing a site on a meteor, trying to add to the database:

var test = [
'1': {test: 1},
'2': {test: 2}
];

But [ ] is added to the database. I add
it like this:
Test.insert({
        object: test
      });

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2015-04-29
@AlexanderKot

If you need to insert an array, then there is an option insertMany

var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  var col = db.collection('collectionName');
  col.insertMany([{a:1}, {a:2}], function(err, r) { ... });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question