Instructions for saving data into MongoDB from imports/ui/pages/.js file

can you provide some basic instructions of setting up, connecting and saving data on Mongodb from a .js file stored in the path imports/ui/pages/.js
From what I read so far it is important if the connection is from the server to the db or from the client to the db,my issue seems from client to the db, i tried a dummy example

const Posts = new Mongo.Collection(‘posts’);
Posts.insert({ title: ‘Hello world’, body: ‘First post’ });

and get

insert failed: Method ‘/posts/insert’ not found

can you give some instructions?I want to save some onclick input data of the user on the interface

This part needs to be on both the client and server for that to work