【发布时间】:2022-01-10 15:48:17
【问题描述】:
我正在尝试获取与给定产品相似的产品列表(与给定产品类型相似),但不包括给定产品。
我的数据库中有 3 个床位实例,因此我想获取它们的其他 2 个实例,但不返回原始 1,在本例中其 ID 为 1。
查看文档后,我认为以下内容可行,但它给了我一个 500 内部错误。
product_type = "Bed"
product_id = 1
client = MongoClient("...")
db = client.assignment
theId = db.products.find({"_id": {"$ne": product_id}})
theProd = db.products.find({"product_type": {"$eq": product_type}})
myCursor = db.products.find({"$and": [theId, theProd]})
list_cur = list(myCursor)
json_data = dumps(list_cur)
return json_data
【问题讨论】:
标签: python mongodb google-cloud-functions