Baiscally making a node.js, mongodb add friends functionality where having the option of list user to add in friends list, sent friends request, accept friends request, delete friends request, block friends request.

**Register Collection**

```
const mongoose = require('mongoose');

const Schema = mongoose.Schema;

let Register = new Schema(
    First_Name:{
        type: String,
        required: true   
    },
    Last_Name: {
        type: String
    },
    Email: {
        type: String,
        unique: true,
        lowercase: true,
        required: true
    },
    Friends:[{type: String}],  
});

module.exports = mongoose.model('Register', Register);

```

**Friends Collection** 

```
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
var ObjectId = require('mongodb').ObjectID;
let Friends = new Schema({
    Requester: {
        type: ObjectId,
        required: true
    },
    Recipients: [{Recipient:{type:ObjectId},Status:{type:Number}}],

}); 
module.exports = mongoose.model('Friends', Friends);

```

**Inside Node.js Post API**

```
var Register = require('../models/register.model');
var Friends =require('../models/friends.model');

router.post('/getdata',function(req,res)
{
let Email="example@example.com";

Register.findOne({ Email : Emails }, function(err, user) {

Friends.findOne({ Requester :user._id  }, function(err, user1) {

Register.find({$and:[{Friends:{$nin:[user._id]}},{_id:{$ne:user1.Recipients.Recipient}}]},function(err, user2) {

console.log("user2",user2);

//Here User2 data is not coming

//How to get data so can able to list user that is not added yet in FriendList

//Mainly user1.Recipients.Recipient this is not working because //Recipients is array so how can match all data with array, if i am //using loop then find return data scope ends on inside find closing //braces only.

//Any suggestion

 });

 });
});

```