是MongoDB线程安全吗?

编程入门 行业动态 更新时间:2024-10-15 10:21:03
本文介绍了是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:

mongodb.onconfluence/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:

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

更多推荐

是MongoDB线程安全吗?

本文发布于:2023-11-12 10:49:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581281.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   MongoDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!