0

I am 15 pages in my site. I want to track the guest user (through IP) & loggedin user (through userid) for all the pages.

What I have schema is:

Create a table;
create one entry;
and make 15 arrays (according to page name);
15 more columns for the visit counter

So after this my collection looks like this:

{
  "_id" : ObjectId("60c6f7a5ef86bd1a5402e928"),
 "sequenceid" : 1,
 "page1": [],
 "page1_counter": 0,
 .
 .
 .
 .
 "page15": [],
 "page15_counter": 0,
}

Whereas array entry will be like:

page1: [
 {userid: '123', ip: '192.168.1.4', timestamp: '04-06-2022'}, // loggedin user entry
 {userid: '', ip: '192.168.1.14', timestamp: '05-06-2022'}, // guest user entry
]

Only Drawback is looking on this is that it will generate the high intensive task for update and fetch data when its size grows.

One of my friend suggested me to make the individual table for all the pages, store entry as a individual fresh entery so that it will free from nested structure in the array.

Like this:

{
 _id: objectId(someid),
 userid: '123', // represent loggedin user
 ip: '192.168.1.4',
 timestamp: 'time'
},
{
 _id: objectId(someid),
 userid: '', // represent guest user
 ip: '192.168.11.41',
 timestamp: 'time'
}

I need the suggestion from the experts that what is the best way to make the table for this type of case. Any help or suggestion is really appreciated. Thanks in advance for the interaction.

2
  • Would you be open to using a relational database instead of MongoDB? This sounds like a simple problem for one.
    – J.D.
    Jun 6 at 11:24
  • @J.D. Actually I am on NoSql database and will have to implement in MongoDB
    – Aks
    Jun 7 at 5:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.