db.collection('basicInfo', function(err, collection){ collection.insert({'id': req.params.id, 'name': req.params.user}, function(error, result){ if(result !== null && result !== ''){ res.send(result); } else{ res.send('Insert error!' + error); } }) })
MongoClient.connect(url, (err, client) => { const coll = client.db("demo").collection("devices"); coll.insert(doc).then(() => client.close()); });
app.post('/', function(request, response) { people.insert({ name: request.body.name, job: request.body.job }, function(err, doc) { if(err) throw err; response.redirect("/"); }); });
// Use connect method to connect to the Server client.connect(function(err) { assert.equal(null, err); console.log('Connected successfully to server'); const db = client.db(dbName); db.collection('demo').insert({demo: 'test'}); client.close(); });
/** * Reset the database. This deletes all data and loads the sample/test data */ app.post("/flintstones", function (req, res) { db.collection("people").remove(function (err, removed) { if (err) { throw err; } else { // console.dir("Successfully removed " + removed + " documents!"); db.collection("people").insert(testData, function (err, result) { // insert takes an object or array of objects if (err) { throw err; } else { // console.dir("Successfully inserted: " + JSON.stringify(result.length) + " documents"); // Note the returned value (result) is an array even if it’s one document res.send(result); } }); } }); });
db.collection('otherInfo', function(err, table){ table.findOne({'id': req.params.id}, function(err, value1){ if(value1 !== null && !err){ table.update({'id': req.params.id},{$set:{'email': req.params.email, 'age': req.params.age, 'title': req.params.title}}, function(err, done){ if(done !== null && !err){ res.send('Updated sucessfully'); } }); } else{ table.insert({'id': req.params.id, 'email': req.params.email, 'age': req.params.age, 'title': req.params.title}, function(err, inserted){ if(inserted !== null && !err){ res.send(inserted); } else{ res.send("Error: "+ err.errmsg); } }) } }) })
insert(col, data, callback) { this.reconnect(()=> { try { this.DB.collection(col).insert(data, (err, result) => { if (err) { try { callback(err); } catch (e) { console.log(err); } } callback(result); }); } catch (e) {} }); }
db.collection('basicInfo', function(err, table){ table.findOne({'id': req.params.id}, function(err, contents){ if(contents !== null){ db.collection('profInfo', function(err, created){ created.insert({'id': req.params.id, 'name': contents.name, 'Org': 'GMX'}, function(err, result){ if(result !== null && !err){ res.send(result); } else{ res.send('Error: ' +err.errmsg); } }) }) } else{ res.send('ID not found in table1'); } }) })
/** * ドキュメントを作成します * * @param {String} collectionName コレクション名 * @param {Object} data * @return {Promise<any>} */ async create(collectionName, data) { if (collectionName == null || data == null) { throw new MissingArgumentsError(); } const result = await this._db.collection(collectionName).insert(data); const document = await this.find(collectionName, { _id: result.ops[0]._id }); return document; }
}; collection.insert(ip, err => { if (err) { throw err;
/* * Add a contact. * */ app.post("/contacts", function (req, res) { var person = req.body; console.log("PUT /contacts, req.body: " + JSON.stringify(person)); db.collection("people").insert(person, function (err, result) { if (err) { throw err; } else { console.dir("Successfully inserted: " + JSON.stringify(result[0])); // Note the returned value (result) is an array even if it’s one document res.send(result[0]); } }); });
/** * @description 新增 * * @param {Object} options * @returns promise */ insert(options) { let self = this; return new Promise((resolve, reject) => { try { self.db.collection(options.table).insert(options.data, options || {}, (err, docs) => { err ? reject({ ok: -1, es: err }) : resolve(docs.result, docs); }); } catch (e) { reject({ ok: -1, es: e }); } }); }
db.collection('Devices').insert(