什么是MongoDBs严格模式,使用它是个好主意? [英] What is MongoDBs strict mode and is it a good idea to use?

查看:222
本文介绍了什么是MongoDBs严格模式,使用它是个好主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个使用MongoDB的node.js应用程序,我从 docs

I'm working on a node.js app that uses MongoDB and I read this from the docs:


db.collection

获取特定集合(包含实际的集合信息)。如果应用程序不使用严格模式,您可以通过以下方式使用它而无需回调。

Fetch a specific collection (containing the actual collection information). If the application does not use strict mode you can can use it without a callback in the following way.

var collection = db.collection('mycollection');

首先,文档指的是什么'严格模式'?

First of all, what 'strict mode' is the doc referring to?

此外,这是一个不好的做法以这种方式抓住收藏品?如果没有回调,在尝试选择正确的集合时,我是否会失去捕获潜在连接错误的能力?

Also, is it a bad practice to grab the collection in this fashion? Without the callback, wouldn't I lose the ability to capture a potential connection error when trying to select the right collection?

db.collection('some_collection', function(err, collection) {
  // query goes here
});


推荐答案

http://mongodb.github.io/node-mongodb-native/api-generated/db.html#收集


严格,(布尔值,默认值:false)如果收集$ $则返回错误b $ b不存在

strict, (Boolean, default:false) returns an error if the collection does not exist

就在文档中。

就是这样,你的应用程序可能不会自己创建新的集合,只能引用之前创建的集合。因此需要回调,以便捕获错误。

That is there so your application may not create new collections itself and can only reference what has been created before. Hence the need for the callback, in order to trap the error.

这篇关于什么是MongoDBs严格模式,使用它是个好主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆