正确解析 Mongo 游标到 PHP
将 MongoCursor 转换为 PHP 时,我使用此脚本。此处介绍的 StackOverflowSO
使用上面的方法,结构相同,但 _id 是,而使用下面的脚本会产生以下包含的结果。
不幸的是,这会导致实际对象被嵌入到带有 Mongo 的 _id 的数组中。像这样:
`4eefa79d76d6fd8b50000007 = {
"_id" = {
"$id" = 4eefa79d76d6fd8b50000007;
};
longText = "Error Description";
nCode = dee29fd7e15ce4ab2d3f7dfa7c5d8fc44b27501ad00908771128c920ef276154;
nStatus = Process;
nText = "E12345";
nVType = Type1;
pId = {
"$id" = 4eefa79676d6fd8b50000003;
};
pushDate = "2011-12-20+06%3A07%3A41";
updateFlag = 1;
};`
由于我将此对象传递给另一个服务来处理 _id 未知。
如何说服 PHP 驱动程序正确解析对象?
When converting a MongoCursor to PHP I use this script. Which was presented here
StackOverflowSO
using the upper method, the structure is same but _id is whereas using the lower script which yields the below included result.
Unfortunately, this results in the actual object being embedded into an array with the _id from Mongo. Like this :
`4eefa79d76d6fd8b50000007 = {
"_id" = {
"$id" = 4eefa79d76d6fd8b50000007;
};
longText = "Error Description";
nCode = dee29fd7e15ce4ab2d3f7dfa7c5d8fc44b27501ad00908771128c920ef276154;
nStatus = Process;
nText = "E12345";
nVType = Type1;
pId = {
"$id" = 4eefa79676d6fd8b50000003;
};
pushDate = "2011-12-20+06%3A07%3A41";
updateFlag = 1;
};`
Since I am passing this object to another service for processing the _id is not known.
How can I convince the PHP Driver to parse the object properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上我所做的就是这样的。
但这创建了上述对象,这不是我需要的。
我就是这样解决的。
返回 json_encode($return);
Basically what I did was this.
But this created the aforementioned object which is not what I needed.
I solved it in this way.
return json_encode($return);
如果为了节省 RAM 你的结果很大,你可以尝试这种更有效的方法:
If you result is big in order to save RAM you could try this more efficient method: