Hello!

I have a collection of this type:

{ _id: ObjectId("53f6ea88efd71760ee000002"), title: "foo", published: "2014-08-22 01:26:21 UTC", image: "s3_foo.jpg", summary: "foo foo", categories: ["foo","bar"], content: "foo sting text", author: "bar", from: ["bar"], shop_id: 12279649167164, } 

I want to get all the records from shop_id: 12279649167164 and their date.

 pry(shop)> @shop_id = "12279649167164" pry(shop)> a = collection.find( {'shop_id' => @shop_id}, fields: ['published'] }).map {|e| pe} pry(shop)> [] 

I do not understand what the problem is. I use Ruby 2.1.2 and mongo-ruby-driver

  • Like decided, like this: @shop_id = [12279649167164] time = co.find ({'url_id' => {'$ all' => @url_id}}, fields: ['published']). Map {| e | pe} - sooik
  • or just time = co.find ({'url_id' => @url_id}}, fields: ['published']). map {| e | pe} - sooik

1 answer 1

The problem is that you specify the string as search criteria

 @shop_id = "12279649167164" 

However, the MongoDB document contains the number

 shop_id: 12279649167164 

Your condition will work if you put a number in the @shop_id variable

 @shop_id = 12279649167164 

Or bring the string to the number

 @shop_id = "12279649167164".to_i