如何将 SQL 语法转换为 Mongo?
How to convert SQL syntax into Mongo?
我在 Rails 和 Mongoid
上使用 Ruby
如何转换此语法以使其与 Mongo 一起使用?
def index
@conversations = Conversation.where("sender_id = ? OR receiver_id = ?", current_user.id, current_user.id)
end
和
def index
@conversation.messages.where("user_id != ? AND read = ?", current_user.id, false).update_all(read: true)
end
找到解决方案:
@conversations = Conversation.where("sender_id = ? OR receiver_id = ?", current_user.id, current_user.id)
改为
@conversations = Conversation.any_of({sender_id: current_user.id}, {receiver_id: current_user.id})
第二行必须完全重写,不能使用。所以不知道行不行
@conversation.messages.where("user_id != ? AND read = ?", current_user.id, false).update_all(read: true)
可能行不通
@conversation.messages.not.where(user_id: current_user.id).where(read: false).update_all(read: true)
我在 Rails 和 Mongoid
上使用 Ruby如何转换此语法以使其与 Mongo 一起使用?
def index
@conversations = Conversation.where("sender_id = ? OR receiver_id = ?", current_user.id, current_user.id)
end
和
def index
@conversation.messages.where("user_id != ? AND read = ?", current_user.id, false).update_all(read: true)
end
找到解决方案:
@conversations = Conversation.where("sender_id = ? OR receiver_id = ?", current_user.id, current_user.id)
改为
@conversations = Conversation.any_of({sender_id: current_user.id}, {receiver_id: current_user.id})
第二行必须完全重写,不能使用。所以不知道行不行
@conversation.messages.where("user_id != ? AND read = ?", current_user.id, false).update_all(read: true)
可能行不通
@conversation.messages.not.where(user_id: current_user.id).where(read: false).update_all(read: true)