mongodb+nodejs

不能只看mongodb官网文档https://docs.mongodb.com/manual/reference/method/db.collection.findOne/,都是同步接口

 

要看node的比如http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#findOne

var MongoClient = require('mongodb').MongoClient,
  test = require('assert');
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
  // Get the collection
  var col = db.collection('find_one_and_delete_with_promise');
  col.insertMany([{a:1, b:1}], {w:1}).then(function(r) {
    test.equal(1, r.result.n);

    col.findOneAndDelete({a:1}
      , { projection: {b:1}, sort: {a:1} }
      ).then(function(r) {
        test.equal(1, r.lastErrorObject.n);
        test.equal(1, r.value.b);

        db.close();
    });
  });
});

 

相关文章

MongoTemplate 是Spring Data MongoDB 中的一个核心类,为 S...
笔者今天要分享的是一个项目重构过程中如何将数据库选型由原...
1.类型区别MySQL是传统的关系型数据库,MongoDB则是非关系型...
在mongodb数据库中操作字段的方法:1.启动mongodb;2.登录mo...
在mongodb中查看指定时间段数据的方法:1.启动mongodb;2.登...
在mongodb中给数据按时间进行排序的方法:1.启动mongodb服务...