在MongoDB中,是否可以使用另一个字段中的值更新字段的值?等效的SQL将是这样的:
UPDATE Person SET Name = FirstName + ' ' + LastName
Run Code Online (Sandbox Code Playgroud)
MongoDB伪代码将是:
db.person.update( {}, { $set : { name : firstName + ' ' + lastName } );
Run Code Online (Sandbox Code Playgroud) 我试图遍历这个循环:
for doc in coll.find()
Run Code Online (Sandbox Code Playgroud)
我在第100,000个加号记录中收到以下错误.
File "build\bdist.win32\egg\pymongo\cursor.py", line 703, in next
File "build\bdist.win32\egg\pymongo\cursor.py", line 679, in _refresh
File "build\bdist.win32\egg\pymongo\cursor.py", line 628, in __send_message
File "build\bdist.win32\egg\pymongo\helpers.py", line 95, in _unpack_response
pymongo.errors.OperationFailure: cursor id '1236484850793' not valid at server
Run Code Online (Sandbox Code Playgroud)
这个错误是什么意思?
我正在尝试使用 pymongo 从 mongodb 读取大约 100 万个文档到 csv 文件。我的代码看起来像:
import csv
from pymongo import MongoClient
from datetime import datetime
from bson import json_util
from tempfile import NamedTemporaryFile
client = MongoClient('mongodb://login:pass@server:port')
db = client.some_mongo_database
collection = db.some_mongo_collection
fromDate = datetime.strptime("2018-05-15 21:00", '%Y-%m-%d %H:%M')
tillDate = datetime.strptime("2018-05-16 21:00", '%Y-%m-%d %H:%M')
query = {
"$or": [
{"LastUpdated": {"$gte": fromDate
, "$lt": tillDate}
},
{"$and": [
{"Created": {"$gte": fromDate
, "$lt": tillDate}
},
{"LastUpdated": None}
]
}
]
}
cursor = collection.find(query, no_cursor_timeout=True)
Run Code Online (Sandbox Code Playgroud)
之后,如果我要这样做: …
我在pymongo中尝试了以下命令:
records= db.collection_name.find({"gender":"female"}).batch_size(5)
Run Code Online (Sandbox Code Playgroud)
但经过几次迭代后给出:
pymongo.errors.CursorNotFound: Cursor not found, cursor id: 61593385827.
Run Code Online (Sandbox Code Playgroud)
如果我尝试timeout=False相同的命令即
records= db.collection_name.find({"gender":"female"},timeout=False).batch_size(5)
Run Code Online (Sandbox Code Playgroud)
它给了
TypeError: __init__() got an unexpected keyword argument 'timeout' error.
Run Code Online (Sandbox Code Playgroud) 我正在使用mongodb(mongoose模块)和节点js
,我使用限制和跳过功能处理大约1,00,00,000个文档(每个1000个).
我的处理很好,但一段时间后它给了我一个错误.
{ MongoError: Cursor not found, cursor id: 62783806111
at Function.MongoError.create (/home/admin/Pictures/duplicayProj1/node_modules/mongoose/node_modules/mongodb-core/lib/error.js:31:11)
at /home/admin/Pictures/duplicayProj1/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:483:72
at authenticateStragglers (/home/admin/Pictures/duplicayProj1/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:429:16)
at Connection.messageHandler (/home/admin/Pictures/duplicayProj1/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:463:5)
at Socket.<anonymous> (/home/admin/Pictures/duplicayProj1/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:339:20)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at addChunk (_stream_readable.js:252:12)
at readableAddChunk (_stream_readable.js:239:11)
at Socket.Readable.push (_stream_readable.js:197:10)
at TCP.onread (net.js:589:20)
name: 'MongoError',
message: 'Cursor not found, cursor id: 62783806111',
ok: 0,
errmsg: 'Cursor not found, cursor id: 62783806111',
code: 43 }
Run Code Online (Sandbox Code Playgroud)
可以任何人告诉我什么是实际问题,因为我没有使用任何与光标匹配的关键字.
提前致谢
我正在使用本机 Node JS 驱动程序(v. 3.0.10)在 Mongo 3.6.6(在一个小的 Mongo Atlas 集群上,未分片)上运行
我的代码如下所示:
const records = await collection.find({
userId: ObjectId(userId),
status: 'completed',
lastUpdated: {
$exists: true,
$gte: '2018-06-10T21:24:12.000Z'
}
}).toArray();
Run Code Online (Sandbox Code Playgroud)
我偶尔会看到这个错误:
{
"name": "MongoError",
"message": "cursor id 16621292331349 not found",
"ok": 0,
"errmsg": "cursor id 16621292331349 not found",
"code": 43,
"codeName": "CursorNotFound",
"operationTime": "6581469650867978275",
"$clusterTime": {
"clusterTime": "6581469650867978275",
"signature": {
"hash": "aWuGeAxOib4XWr1AOoowQL8yBmQ=",
"keyId": "6547661618229018626"
}
}
}
Run Code Online (Sandbox Code Playgroud)
这发生在最多返回几百条记录的查询中。每个记录有几百个字节。
我在网上找了什么问题可能是,但大部分的东西我发现在谈论光标超时对于需要超过10分钟的时间才能完成非常大的操作。我无法从我的日志中确切地说出失败的查询花费了多长时间,但最多只有两秒(可能比这短得多)。
我测试使用与出错的值相同的值运行查询,执行时间explain仅为几毫秒:
"executionStats" : {
"executionSuccess" …Run Code Online (Sandbox Code Playgroud)