我需要更新下面提到的集合的userAns,ansBody字段。条件将具有userId,userQuestions._id和quesId。
{
"_id" : ObjectId("5b9624b56b0fe824352e887a"),
"userId" : ObjectId("5b8fd089ee2e6c07765ba024"),
"userQuestions" : [
{
"testStatus" : NumberInt(1),
"_id" : ObjectId("5b9624b56b0fe824352e887f"),
"questionsId" : [
{
"_id" : ObjectId("5b9624b56b0fe824352e8885"),
"quesId" : ObjectId("5b94f1e97b8adc3d46854518"),
"userAns" : "",
"ansBody" : "",
"ansStatus" : ""
}
我尝试过的
let paramObj={
userId:"5b8fd089ee2e6c07765ba024",
quesSetId:"5b9624b56b0fe824352e887b",
quesId:"5b9619311d9b1b1834f2cd23",
ansId:"5b9619311d9b1b1834f2cd27",
ansBody:"abc123"
}
let questionSet=await QuestionSet.update({userId:paramObj.userId,"userQuestions._id":paramObj.quesSetId},
{ $set: {"userQuestions.$[t].questionsId.$[u].ansBody": paramObj.ansBody} },
{ arrayFilters: [ { "t.quesId":paramObj.quesId },{"u.quesId": paramObj.quesId} ] } );
事件虽然它给了我修改后的输出,但是文档没有得到更新。
答案 0 :(得分:0)
您必须将对象ID传递为ObjectId类型。
为此,如果您使用的是猫鼬,请使用将该字符串转换为猫鼬对象类型。
System.Exception: HandleAndroidException ---> System.ArgumentNullException: Value cannot be null.
Parameter name: method
at System.Linq.Expressions.Expression.Call(System.Linq.Expressions.Expression instance, System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2)[0x0009d] in <c674d6912966428cb26998a802347469>:0
at System.Linq.Expressions.Expression.Call(System.Linq.Expressions.Expression instance, System.Reflection.MethodInfo method, System.Collections.Generic.IEnumerable`1[T] arguments) [0x00074] in <c674d6912966428cb26998a802347469>:0
at System.Linq.Expressions.Expression.Call(System.Linq.Expressions.Expression instance, System.Reflection.MethodInfo method, System.Linq.Expressions.Expression[] arguments) [0x00000] in <c674d6912966428cb26998a802347469>:0
at MvvmCross.Logging.LogProviders.SerilogLogProvider.GetForContextMethodCall() [0x00086] in <df54a54dac96467098c3a9eece96a79b>:0
at MvvmCross.Logging.LogProviders.SerilogLogProvider..ctor() [0x00018] in <df54a54dac96467098c3a9eece96a79b>:0
at MvvmCross.Core.MvxSetup.CreateLogProvider() [0x00045] in <df54a54dac96467098c3a9eece96a79b>:0
at myRouteTracker.Droid.Setup.CreateLogProvider() [0x0002a] in <bdd41c7f90344b17a5e6bc21c3959feb>:0
at MvvmCross.Core.MvxSetup.InitializeLoggingServices() [0x00000] in <df54a54dac96467098c3a9eece96a79b>:0
at MvvmCross.Core.MvxSetup.InitializePrimary() [0x00016] in <df54a54dac96467098c3a9eece96a79b>:0
at MvvmCross.Core.MvxSetupSingleton.StartSetupInitialization() [0x0000a] in <df54a54dac96467098c3a9eece96a79b>:0
at MvvmCross.Core.MvxSetupSingleton.InitializeAndMonitor(MvvmCross.Core.IMvxSetupMonitor setupMonitor) [0x00042] in <df54a54dac96467098c3a9eece96a79b>:0
at MvvmCross.Droid.Support.V7.AppCompat.MvxSplashScreenAppCompatActivity.OnCreate(Android.OS.Bundle bundle) [0x00019] in <2d476ccd46884988a021d78ffc7a2843>:0
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in <1b4c73c9a2864ea8b5827f31fda08c32>:0
at(wrapper dynamic-method) System.Object.e043741f-fba6-4072-a6c2-cfc97949a294(intptr, intptr, intptr)
--- End of inner exception stack trace ---
我认为它将解决您的问题。