我有这种格式的文件:
{
"env" : "local",
....,
"daily" : [
{
"executionParam1" : "Apple",
"executionParam2" : "sour",
"executionParam3" : "today",
...
},
{
"executionParam1" : "Oranges",
"executionParam2" : "sour",
"executionParam3" : "tomorrow",
....
}...
]
我使用MongoDB java驱动程序查询它。查询采用以下形式:
this.mongoDailyReportCollection = this.mongoDb.getCollection("environments");
Bson projection = fields(excludeId(),
include("env", "daily"),
Projections.elemMatch("daily",
and(eq("executionParam1", coll.getexecutionParam1()),
eq("executionParam2", coll.getexecutionParam2()),
eq("executionParam3", coll.getexecutionParam3()))));
long count = this.mongoDailyReportCollection.count(projection);
即使executionParam1是Apple,executionParam2还是今天,executionParam3也是如此,我仍然计算为0。如果我想更新与此文档匹配的文档,那么程序
答案 0 :(得分:0)
您正在将投影文档发送到接受查询文档的[DllImport("user32.dll")]
static extern bool GetKeyboardState(byte[] lpKeyState);
[DllImport("user32.dll")]
static extern uint MapVirtualKey(uint uCode, uint uMapType);
[DllImport("user32.dll")]
static extern IntPtr GetKeyboardLayout(uint idThread);
[DllImport("user32.dll")]
static extern int ToUnicodeEx(uint wVirtKey, uint wScanCode, byte[] lpKeyState, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pwszBuff, int cchBuff, uint wFlags, IntPtr dwhkl);
public static string KeyCodeToUnicode(System.Windows.Forms.Keys key)
{
byte[] keyboardState = new byte[255];
bool keyboardStateStatus = GetKeyboardState(keyboardState);
if (!keyboardStateStatus)
{
return "";
}
uint virtualKeyCode = (uint)key;
uint scanCode = MapVirtualKey(virtualKeyCode, 0);
IntPtr inputLocaleIdentifier = GetKeyboardLayout(0);
StringBuilder result = new StringBuilder();
ToUnicodeEx(virtualKeyCode, scanCode, keyboardState, result, (int)5, (uint)0, inputLocaleIdentifier);
return result.ToString();
}
方法。
count
您将使用带有set修饰符的位置运算符来更新来自查询过滤器的字段匹配。
以下查询会将Bson filter = Filters.elemMatch("daily", and(eq("executionParam1", coll.getexecutionParam1()), eq("executionParam2", coll.getexecutionParam2()), eq("executionParam3", coll.getexecutionParam3())));
long count = this.mongoDailyReportCollection.count(filter);
更新为executionParam1
。
像
这样的东西Banana