Answer the question
In order to leave comments, you need to log in
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}
];
Test.insert({
object: test
});
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question