Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

database - MongoError: Expression $ne takes exactly 2 arguments. 1 were passed in

fitness_goals.aggregate([
  {'$match':{status:1,_id:{'$in':[ObjectId("5f606c24dedd8512595cbf37"),
    ObjectId("5f9fadde6f738924c0b18e0a")]}}},
  {'$unwind':'$recommendedRecipe'},
  {'$group':{_id:null,recipeId:{'$addToSet':'$recommendedRecipe'}}},     
 

Error in this Quoted section

{'$lookup':{from:'recipe_library', let:{recipeId:'$recipeId'},pipeline:[{'$match':{'$expr':{'$and':[{'$in':['$_id','$$recipeId']},{status:1,recipeType:{'$ne':''}}]}}}, {'$limit':1}],as:'recipeData'}},

  {'$project':{ recipeName: { '$arrayElemAt': [ '$recipeData.recipeName', 0 ] },}}
], {})

I was getting error while trying to put this in a formatted manner.

sampledoc

fitnessgoals:

{"_id":ObjectId("5f9fadde6f738924c0b18e0a"),"inCompatibleCategories":[],"recommendedWorkouts":[],"recommendedRecipe":[ObjectId("60085bcc1fb6ef515d49f824")],"noOfworkouts":[],"noOfrecipes":[],"status":1,"goalName":"Be Toned","createdAt":ISODate("2020-11-02T06:57:34.080Z"),"updatedAt":ISODate("2020-12-29T07:03:29.134Z"),"__v":0}, {"_id":ObjectId("5f606c24dedd8512595cbf37"),"goalName":"mental health","tags":"mental health","status":2,"inCompatibleCategories":[],"recommendedRecipe":[ObjectId("600876b8c645e7566434647a"),ObjectId("60085bcc1fb6ef515d49f824")],"recommendedWorkouts":[ObjectId("5f802424b6f11c2e85bc1473"),ObjectId("5f906681bbe83f3d4c75b279")],"updatedAt":ISODate("2020-11-02T06:59:13.827Z")}

RecipesDoc:

{"_id":ObjectId("600876b8c645e7566434647a"),"prepnTime":80,"totalTime":82,"cookingTime":2,"isRecomended":0,"noOfViews":0,"recipeType":'2',"noOfFavourite":0,"noOfTips":0,"noOfCompletion":0,"ratings1":0,"ratings2":0,"ratings3":0,"ratings4":0,"ratings5":0,"instructions":["recipe"],"categoryId":[ObjectId("5fead8c52422823bd0ee216f")],"tags":[],"nutritionServingSize":2,"ingredServingSize":1,"fitnessGoalsId":[ObjectId("5f9fadde6f738924c0b18e0a")],"dynamicPanel":"","status":2,"totalServing":1,"totalRatings":1,"ratedByCount":1,"avgRating":1,"totalCalories":0,"recipeCode":"recipe","recipeName":"recipe","recipeDesc":"recipe","adminId":ObjectId("5e0064311457694f9440f255"),"createdAt":ISODate("2021-01-20T18:30:16.384Z"),"updatedAt":ISODate("2021-01-20T19:10:16.396Z"),"__v":0}, {"_id":ObjectId("60085bcc1fb6ef515d49f824"),"prepnTime":0,"totalTime":10,"cookingTime":10,"isRecomended":0,"noOfViews":0,"recipeType":'1',"noOfFavourite":0,"noOfTips":0,"noOfCompletion":0,"ratings1":0,"ratings2":0,"ratings3":0,"ratings4":0,"ratings5":0,"nutritionServingSize":10,"ingredServingSize":2,"fitnessGoalsId":[ObjectId("5f606c24dedd8512595cbf37")],"dynamicPanel":"","status":2,"totalServing":1,"totalRatings":1,"ratedByCount":1,"avgRating":1,"totalCalories":0,"recipeCode":"hhfeuhfu","recipeName":"hdfdfhuhf","recipeDesc":"rfuhfuhrurhfu","adminId":ObjectId("5e0064311457694f9440f255"),"createdAt":ISODate("2021-01-20T16:35:24.347Z"),"updatedAt":ISODate("2021-01-20T16:36:00.981Z"),"__v":0}

question from:https://stackoverflow.com/questions/65913744/mongoerror-expression-ne-takes-exactly-2-arguments-1-were-passed-in

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...