tomatito
tomatito

Reputation: 411

check if bson array include string id

I would like to know if an array of bsons include a string id, something like this:

[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"

I'm always getting false.

Thank you!

Upvotes: 0

Views: 222

Answers (1)

Martin
Martin

Reputation: 4222

Converting manager_to_remove to BSON::ObjectId works:

require 'bson'
changed = [BSON::ObjectId('5ae9972ea8abbc3c5484cd5e')]
manager_to_remove = BSON::ObjectId("5ae9972ea8abbc3c5484cd5e")
changed.include?(manager_to_remove).inspect # => "true"

Upvotes: 1

Related Questions