我想知道一个bsons数组是否包含字符串id,如下所示:
[186] pry(main)> changed = [BSON::ObjectId('5ae9972ea8abbc3c5484cd5e')]
=> [BSON::ObjectId('5ae9972ea8abbc3c5484cd5e')]
[187] pry(main)> changed
=> [BSON::ObjectId('5ae9972ea8abbc3c5484cd5e')]
[188] pry(main)> manager_to_remove = "5ae9972ea8abbc3c5484cd5e"
=> "5ae9972ea8abbc3c5484cd5e"
[189] pry(main)> manager_to_remove
=> "5ae9972ea8abbc3c5484cd5e"
[190] pry(main)> changed.include?(manager_to_remove).inspect
=> "false"
我总是变得虚假。
谢谢!
答案 0 :(得分:1)
将manager_to_remove
转换为BSON::ObjectId
有效:
require 'bson'
changed = [BSON::ObjectId('5ae9972ea8abbc3c5484cd5e')]
manager_to_remove = BSON::ObjectId("5ae9972ea8abbc3c5484cd5e")
changed.include?(manager_to_remove).inspect # => "true"