Meteor 文档 ID 使用垃圾字符呈现
Meteor document ID is rendered with garbage characters
我使用 Python 脚本将一个集合插入到 MongoDB 中。典型的文档如下所示:
{ _id: { _str: '571eae67ab2c0d18c8509d0f' },
something: '6.10',
area: '1805.80'}
在Python脚本中,id没有明确设置,这个_id
是MongoDB生成的。
现在 _id
在模板中呈现如下:
571eae67ab2c0d18c8509d0f""{}
在 URL 中也是如此。所以当我打开 /record/571eae67ab2c0d18c8509d0f""{}
时,findOne 函数查询 {_id: '571eae67ab2c0d18c8509d0f""{}'}
并没有找到任何东西。
我应该在这个方案中修复什么?
我在这里查找了其他问题,并尝试了这个:
= this._id.toHexString
= _id.toHexString
= _id._str
但它什么也没输出。
使用助手和调试输出我发现 _id
不包含任何类型的对象 ID,而是一个字符串。问题在于 EasySearch 出于自身目的使 _id
变平。
这是一个描述:https://github.com/matteodem/meteor-easy-search/issues/347#issuecomment-152793656
I'm experiencing a problem where the search query is added to end the of all the id's.
When there is nothing in the input box, it's just adds an empty "" at the end of id
And if there is any input, it gets inserted inside the quotation marks.
答案:
Ran into the same "issue" yesterday, it turns out you should use _originalId as the doc says :
EasySearch returns documents when using search that have the same fields as the original ones, but the _id is different. If you want to perform changes on search result documents by the id you can use the __originalId which contains the original _id of the document. So collection.findOne(doc._id) won't work, while collection.findOne(doc.__originalId) would.
The search-appended _id is probably used internally by this package
我使用 Python 脚本将一个集合插入到 MongoDB 中。典型的文档如下所示:
{ _id: { _str: '571eae67ab2c0d18c8509d0f' },
something: '6.10',
area: '1805.80'}
在Python脚本中,id没有明确设置,这个_id
是MongoDB生成的。
现在 _id
在模板中呈现如下:
571eae67ab2c0d18c8509d0f""{}
在 URL 中也是如此。所以当我打开 /record/571eae67ab2c0d18c8509d0f""{}
时,findOne 函数查询 {_id: '571eae67ab2c0d18c8509d0f""{}'}
并没有找到任何东西。
我应该在这个方案中修复什么?
我在这里查找了其他问题,并尝试了这个:
= this._id.toHexString
= _id.toHexString
= _id._str
但它什么也没输出。
使用助手和调试输出我发现 _id
不包含任何类型的对象 ID,而是一个字符串。问题在于 EasySearch 出于自身目的使 _id
变平。
这是一个描述:https://github.com/matteodem/meteor-easy-search/issues/347#issuecomment-152793656
I'm experiencing a problem where the search query is added to end the of all the id's. When there is nothing in the input box, it's just adds an empty "" at the end of id
And if there is any input, it gets inserted inside the quotation marks.
答案:
Ran into the same "issue" yesterday, it turns out you should use _originalId as the doc says :
EasySearch returns documents when using search that have the same fields as the original ones, but the _id is different. If you want to perform changes on search result documents by the id you can use the __originalId which contains the original _id of the document. So collection.findOne(doc._id) won't work, while collection.findOne(doc.__originalId) would. The search-appended _id is probably used internally by this package