Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8270519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:35:23+00:00 2026-06-08T06:35:23+00:00

I have some pretty simple code: from mongoengine import * class Comment(Document): id =

  • 0

I have some pretty simple code:

from mongoengine import *

class Comment(Document):
    id = IntField(primary_key=True)
    text = StringField()

class Message(Document):
    id = IntField(primary_key=True)
    comments = ListField(ReferenceField(Comment))

connect('test_db')

c1 = Comment(id=1)
c1.text = 'message_one'
c1.save()

c2 = Comment(id=2)
c2.text = 'message_two'
c2.save()

m = Message(id=1)
m.comments = [c1, c2]
m.save()

msg = Message.objects.get(id=1)
for comment in msg.comments:
    print comment.id, comment.text

I’ve expected that it will print

1 message_one

2 message_two

but I’ve got

1 message_one

1 message_one

When I use any mongodb admin UI to view database everything seems to be ok:

{ "_cls" : "Message" , "_id" : 1 , "_types" : [ "Message"] ,

"comments" : [ { "$ref" : "comment" , "$id" : 1} , { "$ref" : "comment" , "$id" : 2}]}

I’ve tried to swap c1 and c2 in the code (for example use m.comments = [c2, c1]) and unexpectedly I’ve got the proper output:

2 message_two

1 message_one

Also I’ve tried to not use custom primary key "id" and in both cases everything worked properly.

I am very confused with this bug, it seems it’s something wrong with mongoengine or I’m not using it in a right way. Please, any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:35:26+00:00Added an answer on June 8, 2026 at 6:35 am

    There was a bug in dereferencing and this was fixed in 0.6.15 – please upgrade!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some pretty simple code that reads lines from a network stream that
Pretty simple question. I have a few ASP RequiredFieldValdators checking some text boxes. Out
I have some pretty simple Java code in which I'm starting another process and
These are probably are pretty simple YES|NO type questions. I have some NSDictionaries containing
I have a pretty simple UIScrollView defined inside Interface Builder. I've pasted in some
this is just some pretty standard code I have tried. What I am trying
I have written a pretty simple code to get the first result for any
I have some pretty basic C++ code: #include <iostream> #include <string.h> #include <msclr\/marshal_cppstd.h> #using
I've made some pretty checkboxes using some pretty simple jQuery HTML <span class=iconElement checkBox
I have some js (show/hide pretty standard I guess): <script> function showTransactions(transactions){ $('.steps').hide() $('#'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.