是MongoDB线程安全吗? [英] Is MongoDB thread-safe?

查看:415
本文介绍了是MongoDB线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows上运行MongoDB。



使用 mongo.exe show collections()命令,我看到有相同名称的多个集合(超过1,000个同名的集合)。



运行validate时:

 > db.MY_COLLECTION.validate()

我得到:


$ b b

  {errmsg:ns not found,ok:0,valid:false} 

size()命令返回0, find()不返回任何内容。



我的问题是:MongoDB线程安全吗?下面的问题会是像我这样做正确(删除和重新创建)或有更好的方法来刷新集合的整个内容吗?

解决方案

从mongodb文档:



线程安全 b
$ b

只有少数C#Driver类是线程安全的。其中:MongoServer,MongoDatabase,MongoCollection和MongoGridFS。你将使用很多不常用的线程安全的类包括MongoCursor和所有的类从BSON库(除了BsonSymbolTable这是线程安全的)。除非明确记录为线程安全,否则类不是线程安全的。



所有类的所有静态属性和方法都是线程安全的。



您可以在此页面上搜索Thread:



http://mongodb.onconfluence.com/pages/viewpage.action?pageId=18907708&navigatingVersions=true#CSharpDriverTutorial-Threadsafety


I'm running MongoDB on Windows. I have 1 or more threads that drop and recreate a collection.

Using mongo.exe with the show collections() command, I'm seeing multiple collections with the same name (well over 1,000 collections with the same name!).

When I run validate:

> db.MY_COLLECTION.validate()

I get:

{ "errmsg" : "ns not found", "ok" : 0, "valid" : false }

The size() command returns 0, and find() returns nothing.

My question is: Is MongoDB thread safe? A follow on question would be something like 'Am I doing this correctly (dropping and recreating) or is there a better way to refresh the whole content of a collection?'

解决方案

From mongodb documentation:

Thread safety

Only a few of the C# Driver classes are thread safe. Among them: MongoServer, MongoDatabase, MongoCollection and MongoGridFS. Common classes you will use a lot that are not thread safe include MongoCursor and all the classes from the BSON Library (except BsonSymbolTable which is thread safe). A class is not thread safe unless specifically documented as being thread safe.

All static properties and methods of all classes are thread safe.

You can search for the word Thread on this page:

http://mongodb.onconfluence.com/pages/viewpage.action?pageId=18907708&navigatingVersions=true#CSharpDriverTutorial-Threadsafety

这篇关于是MongoDB线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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