这是mongoDB驱动程序文档中的一个示例.我一直试图找出assert.equal在示例中的作用,但是Node.js网站上的官方文档对我没有太多帮助 - 官方文档说"用等同比较运算符测试浅,强制相等(==)." 所以我首先怀疑它会根据相等的真值重新判断是真还是假.但它似乎没有.
我确实看过这篇文章:在nodejs中使用断言模块?.它确实有所帮助 - 但还不够.我仍然不太明白"单元测试"是如何完成的.任何帮助将不胜感激,但坚实的例子将是非常有用的!
var Db = require('mongodb').Db,
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
ReplSetServers = require('mongodb').ReplSetServers,
ObjectID = require('mongodb').ObjectID,
Binary = require('mongodb').Binary,
GridStore = require('mongodb').GridStore,
Grid = require('mongodb').Grid,
Code = require('mongodb').Code,
BSON = require('mongodb').pure().BSON,
assert = require('assert');
// Set up the connection to the local db
var mongoclient = new MongoClient(new Server("localhost", 27017), {native_parser: true});
// Open the connection to the server
mongoclient.open(function(err, mongoclient) {
// Get the first db and do an update …Run Code Online (Sandbox Code Playgroud)