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 6357335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:08:45+00:00 2026-05-24T23:08:45+00:00

Trying out filters for replication, I stumbled upon a problem. While my filter is

  • 0

Trying out filters for replication, I stumbled upon a problem.
While my filter is working as an entry in the _replicator database, I doesn’t when using cURL.

The filter in the design document is:

{
    "_id": "_design/partial",
    "filters": {
        "mobile": "function(doc, req) { 
            if (doc._attachments) {
                var result = new Boolean(true);
                for (attachment in doc._attachments) {
                    if (attachment.content_type == 'image/jpeg') {
                        return true;
                    }
                    if (doc._attachments.length > 1024) {
                        result = false; 
                    }
                }
                return result;
            } else {
                return true;
            }
        }"
    }
}

The cURL line:

curl -X POST http://admin:pass@192.168.178.13:5985/_replicate -d '{\"source\":\"http://admin:pass@192.168.2:5984/docs2\",\"target\":\"docs2_partial\",\"filter\":\"partial/mobile\",\"create_target\":true}' -H "Content-Type: application/json"

I created _design/partial document on both target and source, but all documents are being replicated. Even the one with an attached binary bigger than 1 MB.
Any help is appreciated!

The cURL reply is:

{"ok":true,"session_id":"833ff96d21278a24532d116f57c45f31","source_last_seq":32,"replication_id_version":2,"history":[{"session_id":"833ff96d21278a24532d116f57c45f31","start_time":"Wed, 17 Aug 2011 21:43:46 GMT","end_time":"Wed, 17 Aug 2011 21:44:22 GMT","start_last_seq":0,"end_last_seq":32,"recorded_seq":32,"missing_checked":0,"missing_found":28,"docs_read":28,"docs_written":28,"doc_write_failures":0}]}

Using either ” instead of \” or ” instead of ‘ the result is:

{"error":"bad_request","reason":"invalid UTF-8 JSON: [...]}
  • 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-24T23:08:45+00:00Added an answer on May 24, 2026 at 11:08 pm

    Now I think perhaps the logic of your filter function simply has a bug. Here is how I read your filter policy:

    • All docs that have no attachments pass
    • All docs that have an image/jpeg attachment pass
    • Docs with more than 1,024 attachments fail
    • In any other case, the docs pass

    That sounds like perhaps an incorrect policy. Another way to restate this policy is “Docs with more than 1024 attachments fail, everything else passes.” However since you wrote so much code, I suspect my summary is not the true policy.

    Another quick note, on what looks like a bug. Given:

    for (attachment in doc._attachments) { /* ... */ }
    

    The attachment variable will be things like “index.html” or “me.jpeg”, i.e. filenames. To get the attachment content-type, you need:

    var type;
    
    // This is WRONG
    type = attachment.content_type; // type set to undefined
    
    // This is RIGHT
    type = doc._attachments[attachment].content_type; // type set to "text/html" etc.
    

    To avoid this bug, you could change your code to make things more clear:

    for (attachment_filename in doc._attachments) { /* ... */ }
    

    Next, doc._attachments.length will tell you the number of attachments in the document, not for example the length of the current attachment. It is odd that you test for that inside the loop, because the expression will never change. Are you trying to test for attachment size instead?

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

Sidebar

Related Questions

While trying out an experimental UINavigationController-based iPhone application, I ran into a problem when
I'm trying out ASP.NET MVC routing and have of course stumbled across a problem.
I'm trying figure out how to query Salesforce with multiple filters where either filter
We are trying to filter out some suspicious bogus fields in our database. And
I am using a filter script and I am trying to alter the jquery
I'm trying to figure out how to structure a program using Java's generics, and
I'm trying to use multiple filters on a CollectionView - using this approach: http://bea.stollnitz.com/blog/?p=32
I am trying to get dependency injection working on my action filters with property
I'm trying to set up a filter using jQuery. I'll have a certain amount
I'm trying to write an MQL query that filters out null values. The query

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.