Creating Views in Mongodb is not working

Can someone please suggest on how beneficial creating view would be.

I have a collections with ~30M documents. When i created a view it is not even being listed.but i got a message saying {OK} but db.currentOp() is also Inprog as empty array.

Any suggestions would be greatly appreciated.

Show the code you used to create the view.

Here is the script which I have used @Jack_Woehr

db.createCollection(
“order_trans_view”,
{
“viewOn” : “order_trans”,
“pipeline” : [
{
$unwind: {
path: “$lineItems”,
preserveNullAndEmptyArrays: false,
},
},
{
$project:
/**
* specifications: The fields to
* include or exclude.
*/
{
lineItemsdeviceId: {
$ifNull: [
“$lineItems.deviceId”,
“null”,
],
},
…Required field like above
},
},
],
// “collation” : { }
}
)

//db.order_trans.find()

This code snippet is messed up. Can you please paste in a little more carefully and use the code widget “</>” to make it easier to read? And please do not use Windows “smart quotes” in your samples.

db.createCollection(
  "PMP_view",
  {
    "viewOn" : "payee_mapped_transactions",
    "pipeline" : [
        {
   $match:
     {
       periodId: "xxxx",
     },
  },
  
  {
    $project:   
      {
        _id: "$_id",
        periodId: "$periodId",
        repAttuid: "$repAttuid",
             },
  },
  
],
   // "collation" : { <collation> }
  }
)

I have tried the same script in local and it is working fine but in the actual environment where the collection are sharded it is not inserting records only view is getting created.

Hmm, I am not sure what could be causing that. Misconfiguration of the remote environment?