Is it possible to add a new document or parameter to the user.profile from the client in Meteor.js and Mongo?

Is it possible to insert an array of a user's links into the current user's profile?

I attempted the following on the client side, but it did not work:

Meteor.users.update( {_id: Meteor.userId()}, {
        $set: {
            profile: {
                userlinks: {
                    owned: "_entry_id"
                }
            }
        }
    });

I also tried using insert instead of update, but with no success.

I have some ideas about what could be causing the issue:

  • Possibly, I am not setting the mongodb permissions correctly (least likely)
  • It is possible that I am not publishing the user collection correctly (since I currently don't publish it at all) and maybe Meteor doesn't do this automatically (somewhat likely)
  • Insert might be the correct command, but limited to the server. Therefore, I may need to place the insert function inside a Meteor method on the server and then call that method from the client (more likely)

Or perhaps, I just lack understanding of what I am doing (most likely)

Answer ā„–1

Make sure to refer to the Meteor Update Docs for correct syntax guidelines. Here is a corrected version:

var id = Meteor.userId();
Meteor.users.update( id, {
        $set: {
            profile: {
                userlinks: {
                    owned: "_entry_id"
                }
            }
        }
    });

Answer ā„–2

To enable this functionality, ensure that your user has a profile field set up when using a custom account UI. When authenticating a user, make sure to set the profile to at least an empty object initially.

var options = {
    username: 'some_user',
    password: 'password',
    email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9df8f0fcf4f1ddf9f2f0fcf4f3b3fef2f0">[email protected]</a>',
    profile: {}
}

Accounts.createUser(options, function(err){
    if(err){
        //do error handling
    }
    else
        //success
});

If you have removed the insecure package, remember to establish Meteor.users.allow in order for users to update themselves:

Meteor.users.allow({
    update: function(userId, doc, fieldNames, modifier){
        if(userId === doc._id && fieldNames.count === 1 && fieldNames[0] === 'profile')
            return true;
    }
})

This setup ensures that users can only update their own profiles.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Interact with the screen by moving your mouse or sw

I am absolutely intrigued by this captivating visual effect. My goal is to implement this on an iPhone or iPad using touchmove functionality. Is there anyone out there who can assist me with this task? Here is the JavaScript code snippet: $(document).bin ...

Error message: Unknown scope- unable to process 'files-path' Android File provider issue

My current project involves implementing file system access in react native Android. However, when attempting to add 'files-path' in XML, an error stating "Error: Unsupported type 'files-path'" is encountered. I am utilizing the react n ...

When viewing an array, the objects' values are displayed clearly; however, when attempting to access a specific value, it

I am attempting to retrieve the board_id of my objects in the columnsServer array... columnsServer: Column[]; this.service.getColumns() .subscribe(data => { this.columnsServer = data; console.log(this.columnsServer); for (this.i = 0; this.i ...

Is there a way to disregard the data returned from previous AJAX calls?

I've been wondering about a strategy for managing delayed AJAX data returns in a scenario where newer calls should take precedence over earlier ones. For instance, if a first data fetch initiated at 12:01:33 is delayed and comes back at 12:01;39, whil ...

jQuery encountering TypeError while attempting to retrieve JSON data

Attempting to retrieve JSON data from the following URL using the provided code snippet: $.ajax({ type: "GET", url: "https://covid.ourworldindata.org/data/owid-covid-data.json/", success: function (data) { $("h5").e ...

html line breaks $.parseJSON

Within my website, I am currently utilizing a TinyMCE window. The method involves PHP fetching an entry from the database, decoding it as JSON, and then having in-page JavaScript parse it. However, issues arise when there are elements like style='colo ...

Tips for breaking down a collection of objects and nested arrays into distinct arrays containing individual pieces of data

I have a list of objects structured like this: [ { alert_count: 3, alert_level: {value: 0, label: "ignore"}, count_dates: (3) ["2021-04-21T14:36:02.446Z", "2021-04-21T14:36:12.039Z", "2021-04-21T14:37:04.495Z"], sound_type: {_id: "606331d ...

When an item in the accordion is clicked, the modal's left side scroll bar automatically scrolls to the top. Is there a solution to prevent this behavior and

When I first load the page and click on the Sales accordion, then proceed to click on Total reported and forecasted sales, the scrollbar jumps back up to the top The marked ng-container is specifically for the UI of Total reported and forecasted sales He ...

Creating a personalized function for updating queries using Spring Data's MongoRepository

I have implemented org.springframework.data.mongodb.repository.MongoRepository and added some custom methods as shown below: public interface DocRepository extends MongoRepository<Doc, String> { Doc findByDocIdAndAssignmentId(final String docId ...

Updating the parent's data by modifying data in the child component in VueJS

When I use multiple components together for reusability, the main component performs an AJAX call to retrieve data. This data is then passed down through different components in a chain of events. <input-clone endpoint="/api/website/{{ $website->id ...

Encountering an error when using setState with React.createElement: invalid type provided

https://i.sstatic.net/YHssU.png Anticipated Outcome Upon clicking the login button without inputting an email or password, the user is expected to view the Notification component. Actual Outcome Upon clicking the login button, the setState function is ...

Tips for removing a checkbox and customizing a label's style when the label wraps around the checkbox input

Hello, I'm an advanced beginner so I appreciate your patience:) I've had success removing checkboxes and styling their labels when the for="" attribute is present. However, I'm facing a challenge with a form where the labels wrap the input ...

Issue with styled-components not being exported

Issue: ./src/card.js There was an import error: 'Bottom' is not exported from './styles/cards.style'. card.js import React from 'react' import { Bottom, Color, Text, Image } from "./styles/cards.style"; fu ...

How to send GET parameters to JavaScript

In my script, I am using the GET method to fetch a query string from the URL like this: index.php?page=quiz After retrieving the value of page= (which is quiz in this case), I want to execute my JavaScript function called getPage. Therefore, I have an o ...

Tips on sending filter parameters from AngularJS to Spring RestController using @MatrixVariable

Iā€™m struggling to figure out how to use $http.get in AngularJS to pass filter parameters. The URL is: http://localhost:8080/template/users/query;username=abcd;firstName=ding... The RestController looks like this: @RequestMapping(value={"/users/{query ...

Develop various Checkboxes using JavaScript

I am attempting to dynamically create multiple checkboxes using JavaScript. I have written the following code: var response= data; var container = document.createElement('div'); var checkboxContainer = document.createElement(&apo ...

Ways to split text across lines within my list

I am currently developing a shopping list app and everything is running smoothly. However, I am encountering an issue with breaking a long string into the next line. Even though I tried using word-wrap, it doesn't seem to work as intended. For exampl ...

Incrementing values in ng-repeat object automatically

My project involves extracting game information from mlb.com and utilizing angularjs along with the ng-repeat directive to display it. A sample of the JSON feed is shown below. { "data": { "games": { "next_day_date": "2017-08-19", "mo ...

The process of removing the _id field from an object retrieved from mongodb appears to be ineffective

Recently, I've been working with graphql to fetch data from a mongodb database. While creating an API that saves data in the main collection and another one along with additional data, I encountered an issue. I tried to remove the `_id` field from the ...

Having difficulty retrieving a nested child element with querySelector in JavaScript

Encountering an issue with the querySelector method in JavaScript when accessing nested child elements. The goal is to retrieve the first child of a selected element and then obtain the first child of that inner element. Attempted code: let selected = doc ...