How can I create database view in mongodb using mongoid driver in ruby?

49 Views Asked by At

MongoId version: 7.4.0

In my service class I have this initalize method

  def initialize(auth_context = nil)
    super()
    @db = Mongoid::Clients.default
  end

  def get_order_view
    pipeline = [{
      :'$project' => {
        :_id => 1,
        :product_id => 1,
        :product_name => 1,
        :quantity => 1,
        :amount => 1,
      }
    }]
   @db[:orders].view(
     'get_orders_by_ids_view',
     pipeline
   )
 end

But i am getting this error

"unexpected error occured, exception: 'undefined method `view' for #<Mongo::Collection:0x11100 namespace=demo-contract-manager.contracts>''"
0

There are 0 best solutions below