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

  • SEARCH
  • Home
  • 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 7697957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:07:50+00:00 2026-05-31T22:07:50+00:00

I have a model: class SimpleAction include Mongoid::Document field :set_date, :type => Date and

  • 0

I have a model:

class SimpleAction
  include Mongoid::Document
  field :set_date, :type => Date

and I have some data in collection:

{ “_id” : ObjectId(“4f6dd2e83a698b2518000006”), “name” : “lost”,
“notes” : “”, “set_date(1i)” : “2012”, “set_date(2i)” : “3”,
“set_date(3i)” : “25”, “set_date(4i)” : “13”, “set_date(5i)” : “57”,
“duration” : 15, “todo” : “4” }

You can see that mongoid store date in the five fields – set_date(ni).

I have two question:

  • How can I filter data by set_date field in the mongo console client? Something like this:

    db.simple_actions.find({ set_date : { "$lte" : new Date() } })
    

    My query didn’t return any data.

  • How can I filter data by set_date field in my Rails controller? Something like this:

    @simple_actions = SimpleAction.where(:set_date => { '$lte' => Date.today })
    
  • 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-05-31T22:07:52+00:00Added an answer on May 31, 2026 at 10:07 pm

    I would recommend not using Date, but instead DateTime:

    field :set_date, :type => DateTime
    

    Now not only will it be stored in 1 field, like so:

    "set_date" : ISODate("2012-03-14T17:42:27Z")
    

    But Mongoid will correctly handle various conversions for queries like you want:

    SimpleAction.where( :set_date => { :$lte => Date.today } )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model class Place, which has a field for state, and I
I have 2 model: class Sideshow_manager(models.Model): url_id = models.CharField(max_length=250,editable=False,unique=True) title = models.CharField(max_length=250) date =
I have this model: class Entry(db.Model): title = db.StringProperty() url = db.URLProperty() date =
I have this model class User include DataMapper::Resource include BCrypt property :id, Serial property
I have a model: class Tag(models.Model): name = models.CharField(max_length=50,primary_key=True) #Some other fields.... Then i
I have a model class with a persisted DateTime field that is only interacted
I have a model: class Example(models.Model): unique_hash = models.CharField(max_length=32,unique=True) content = models.FileField(upload_to='source',blank=True,verbose_name=HTML Content File)
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
Assume I have a Model class called Bird and a instance of Bird called
Let's say I have a model class called Project, but instead of this: class

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.