Question: i have a mongodb collection that I sort by the amount of points each item has, and it shows a rank according to it's place in the collection :

```
db.collection('websites').find({}).sort({  "points": -1 }).forEach(doc => {

  rank++;
  doc.rank = rank;
  delete doc._id;
  console.log(doc)

```

[![enter image description here](https://i.stack.imgur.com/ed25g.png)](https://i.stack.imgur.com/ed25g.png)

Si I thought to myself : **Ok, I'm gonna update the rank in the collection**, so I added this :

```
 db.collection('websites').updateMany({},
    { $set: { rank: doc.rank } }
)

```

But I was too good to be true, and it updates every single item with the same rank, which changes at each refresh, what exactly is going on, here ?

[![enter image description here](https://i.stack.imgur.com/0kZee.png)](https://i.stack.imgur.com/0kZee.png)
[![enter image description here](https://i.stack.imgur.com/Qcg09.png)](https://i.stack.imgur.com/Qcg09.png)

**EDIT : I managed to do it by doing this :**

```
rank = 0;

db.collection('websites').find({}).sort({  "points": -1 }).forEach(doc => {

  rank++;
  doc.rank = rank;
  //delete doc._id;
  console.log(doc._id);

  db.collection('websites').updateMany({_id : doc._id},
    { $set: { rank: doc.rank } },
    { upsert: true }
)

})

```

Answer: 
To test CORS locally, I found this repo: <https://github.com/njgibbon/nicks-cors-test>

Just clone it, and click on the `html` file so it opens in your browser. By default it is calling the `github API` (<https://api.github.com>) and fetching info from there. You can open the console and check it.
If you change it to `https://google.com` it will throw a CORS restriction.

Similarly, you can change it to `http://localhost:3000/api/v1/users` (in my case) and it will throw a CORS error with the config I have now.

To double-check, just go to `cors.rb` and put `origins "*"`. Restart the app server and try running again the html file. Now we won't be blocked.
Make an API call from browser (Not from URL and Not from postman). May be through ajax to test.

```
Postman does not implement the CORS restrictions

```