I wanted to select specific columns from an array.
Document:
N1QL:
I don’t want the field “type” within images. How can i achieve this ?
             
            
              
            
           
          
            
            
              You’ll have to have the whole array in a field… I’ve used brandinfo here.
SELECT b.brandId, b.category
FROM yourbucket UNNEST brandinfo b
WHERE b.type = 'Brand' 
            
              
            
           
          
            
            
              Thanks keshav.
But unnest modifies the structure of images from an array.
I expect the result to be the same document (with the same structure), except the ‘type’ field within images array.
Result expected:
             
            
              
            
           
          
            
              
                prasad  
              
                  
                    August 24, 2016,  8:45am
                   
                  4 
               
             
            
              Hi @g.radhakrishnan ,
             
            
              
            
           
          
            
            
              That’s great… Thanks prasad.
Can you please suggest how to remove/exclude multiple fields?
SELECT brandId, category, 
ARRAY object_remove(x, "type") FOR x IN images END AS images
FROM bucket_name 
WHERE type='Brand'; 
            
              
            
           
          
            
              
                prasad  
              
                  
                    August 24, 2016,  4:50pm
                   
                  6 
               
             
            
              Use object_remove() in a nested fashion:
SELECT brandId, category, ARRAY OBJect_remove(OBJect_remove(x, "type"), "target") FOR x IN images END as images
FROM bucket_name WHERE type='Brand'; 
            
              
            
           
          
            
            
              I have one more question.
N1QL:
SELECT offer_catalogue_dev.* FROM sample_bucket WHERE type='Outlet';
Result:
[
  {
    "airport": "Changi Airport T1",
    "externalId": "extId001",
    "outletId": 1,
    "partnershipId": "1",
    "type": "Outlet"
  },
  {
    "airport": "Changi Airport T2",
    "externalId": "extId002",
    "outletId": 2,
    "partnershipId": "2",
    "type": "Outlet"
  }
]
N1QL:
SELECT object_remove(offer_catalogue_dev, 'type') FROM sample_bucket WHERE type='Outlet';
Result:
[
  {
	"$1": {
		"airport": "Changi Airport T1",
		"externalId": "extId001",
		"outletId": 1,
		"partnershipId": "1"
	}
  },
  {
	"$1": {
		"airport": "Changi Airport T2",
		"externalId": "extId002",
		"outletId": 2,
		"partnershipId": "2"
	}
  }
] 
            
              
            
           
          
            
              
                prasad  
              
                  
                    August 25, 2016,  7:03am
                   
                  9 
               
             
            
              Try this (similar to your first n1ql statement):
             
            
              
            
           
          
            
              
                d4nyll  
              
                  
                    June 18, 2018, 12:30pm
                   
                  11 
               
             
            
              Instead of using OBJECT_REMOVE, you can use OBJECT_CONCAT to select only the fields you want. Running a single operation is more performant and more readable than nesting OBJECT_REMOVE functions.